package com.liao.cloudstorage.conf;

import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @author liao
 *
 */
@Configuration
public class MinioClientBean {
    @Value("${minio.endpoint}")
    private String endpoint;
    @Value("${minio.accessKey}")
    private String accessKey;
    @Value("${minio.secretKey}")
    private String secretKey;

    public static String grafana_url;

    public static String prometheus_url;

    @Value("${minio.grafana_url:error}")
    private void setGrafanaUrl(String minioUrl){
        MinioClientBean.grafana_url = minioUrl;
    }

    @Value("${minio.prometheus_url:error}")
    private void setPrometheusUrl(String prometheusUrl){
        MinioClientBean.prometheus_url = prometheusUrl;
    }


    /**
     * 获取minio客户端
     *
     * @return MinioClient
     */
    public MinioClient getMinioClient() {
        try {
            return new io.minio.MinioClient(endpoint, accessKey, secretKey);
        } catch (InvalidEndpointException | InvalidPortException e) {
            e.printStackTrace();
        }
        throw new NullPointerException();
    }
}
